package mysql

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"gorm.io/gorm/logger"
	"month6/common/nacos"
)

var DB *gorm.DB

func InitMysql() {
	var err error
	nac := nacos.Config.Mysql
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", nac.User, nac.Password, nac.Host, nac.Port, nac.Database)
	DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
		Logger: logger.Default.LogMode(logger.Info),
	})
	DB.AutoMigrate(&Super{}, &Class{}, &Coupon{}, &Rob{}, &User{}, &Browse{}, &Order{})
	if err != nil {
		panic(err)
	}
	fmt.Println("mysql success")
}
